$(document).ready(function(){  

    if(do_gallery){
        $("#pikame").PikaChoose({showCaption: false, autoPlay: false, carousel: true})
    }
    


    // Hotel reviews
    var reviews_active = false;
    $(".view_all_reviews").live('click',function(){
    
        if(reviews_active){
        
            reviews_active = false;
            $(this).text('See all reviews');
            $('#hotel-reviews').hide();
            $('#swich_hotel_content').show();
            $('.top-book-now').show();
        
        }else{
        
            reviews_active = true;
            $(this).text('Back to hotel');
            $('#hotel-reviews').show();
            $('#swich_hotel_content').hide();
            $('.top-book-now').hide();
        
        }
    
    });
    
    $('#f_name').val("");
    $('#l_name').val("");
    $('#score').val('9.0');
    $('#comments').val("");
    
    var formbutton = '#sub_reviews';
    var submit_disabled = false;
    
    
    $(formbutton).live('click',function(){
        if(!submit_disabled)
            $('#review_form').submit();
    })
    
    //FORM VALIDATION
    $("#review_form").validate({
        rules: {
            f_name: 'required', 
            l_name: 'required', 
            comments: 'required'
               
        }, 
        highlight: function(element) {
            $(element).addClass("error");
        },
        unhighlight: function(element) {
            $(element).removeClass("error");
        },
        submitHandler: function() {
            
            submit_disabled = true;
            
            $(formbutton).busy({
                img:API.Data.base_url+'assets/img/backgnds/busy.gif',
                position : 'left'
            });

            var my_form = $("#review_form");
            var form_data = my_form.serialize();
            var url = my_form.attr('action');
            
            $.ajax({
                url: url,
                data:form_data,
                dataType: 'json',
                success: function(data){
                    
                    $(formbutton).busy('hide');
                    
                    if(data.success){
                        alert('Thank you for your comment.');
                        window.location.reload();
                    }else{
                        alert('Please try againg.');
                        submit_disabled = false;
                    }
                    
                    
                
                }
            });
               
            return false;
        },
        errorPlacement: function(error, element){}
    });

});